Optimize hash_pbkdf2() by reusing HMAC contexts#21175
Open
gregharmon wants to merge 5 commits intophp:masterfrom
Open
Optimize hash_pbkdf2() by reusing HMAC contexts#21175gregharmon wants to merge 5 commits intophp:masterfrom
gregharmon wants to merge 5 commits intophp:masterfrom
Conversation
TimWolla
reviewed
Feb 9, 2026
Member
TimWolla
left a comment
There was a problem hiding this comment.
Since this is security-sensitive code: Can you please split the individual optimizations into separate commits for ease of review?
- Migration from float to integer operations to calculate the digest lengths.
- HMAC context reuse
- SHA-256 special case
- CommonCrypto SHA-256 special case
- Possibly other individually useful migration steps that I missed
Author
|
Follow-up with exact commit references for easier navigation:
And |
daa2d0f to
1e94d0b
Compare
TimWolla
reviewed
Feb 9, 2026
Member
TimWolla
left a comment
There was a problem hiding this comment.
Thank you for splitting the commits. Some more superficial review. I'll need to take a deeper look at the logic when it isn't almost midnight.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9604.
Optimize
hash_pbkdf2()inext/hashby reusing precomputed HMAC contexts instead of rehashing key blocks each round.Changes
ext/hash/tests/gh9604.phpt.Behavior
No API or semantic changes intended: validation, return formats, and output bytes are unchanged.
Tests
make test TESTS="ext/hash/tests/hash_pbkdf2_basic.phpt ext/hash/tests/hash_pbkdf2_error.phpt ext/hash/tests/gh9604.phpt"make test TESTS="ext/hash/tests"Benchmark
Setup:
hash_pbkdf2('sha256', 'password', 'salt', 200000, 64, false)hrtime(true), median reportedObserved on this machine:
135.47 msmedian28.28 msmedian-of-12 (sample medians27.68–28.46 ms)~4.79x